﻿using Abp.Domain.Repositories;
using Batman.Cache;
using Batman.Cache.Attributes;
using Batman.Core;
using Batman.Jianbei.Forum.Core.ChatRoom;
using Batman.Jianbei.Forum.DTOS.Chatroom;
using System.Collections.Generic;
using System.Linq;

namespace Batman.Jianbei.Forum.Services.ChatRoom.CacheQs
{
    /// <summary>
    /// 聊天室统计查询服务
    /// </summary>
    public class CountQueryCacheQs : ICacheWorkable, Abp.Dependency.ISingletonDependency
    {
        public IRepository<RoomMask, string> RoomMaskRepo { get; set; }

        /// <summary>
        /// 获取(全部未解散的)房间在线人数统计
        /// </summary>
        [Cacher(CacherType.Cache)]
        public virtual List<IdCountDTO> GetRoomsMemberCounts()
        {
            var query = RoomMaskRepo.GetQuery().Where(t => t.IsInRoom && !t.Room.IsDismiss);

            var result = query.GroupBy(t => t.RoomId).Select(t => new IdCountDTO(t.Key, t.Count())).ToList();

            return result;
        }
    }
}
